﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>屏显音量(OSD) - 脚本示例 | AutoHotkey v2</title>
<meta name="description" content="The volume on-screen-display (OSD) script allows pressing a hotkey to raise and lower the master and/or wave volume displayed as different color bar graphs." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>屏显(OSD) 音量---基于 v1 脚本<span class="headnote">作者: Rajat</span></h1>

<p>此脚本把您选择的热键设置为增加和降低总音量和/或波形音量. 这两种音量以不同的颜色条图形显示.</p>
<p><a href="VolumeOSD.ahk">下载此脚本</a> &nbsp;| &nbsp;<a href="index.htm">其他示例脚本</a> &nbsp;| &nbsp;<a href="../AutoHotkey.htm">主页</a></p>

<pre class="NoIndent"><em>; --- User Settings ---

; The percentage by which to raise or lower the volume each time:</em>
global config := {Step: 4}

<em>; How long to display the volume level bar graphs:</em>
config.DisplayTime := 2000

<em>; Master Volume Bar color (see the help file to use more precise shades):</em>
config.CBM := "Red"

<em>; Wave Volume Bar color:</em>
config.CBW := "Blue"

<em>; Background color:</em>
config.CW := "Silver"

<em>; Bar's screen position. Use "center" to center the bar in that dimension:</em>
config.PosX := "center"
config.PosY := "center"
config.Width := 150  <em>; width of bar</em>
config.Thick := 12   <em>; thickness of bar</em>

<em>; If your keyboard has multimedia buttons for Volume, you can
; try changing the below hotkeys to use them by specifying
; Volume_Up, ^Volume_Up, Volume_Down, and ^Volume_Down:</em>
config.MasterUp := "#Up"      <em>; Win+UpArrow</em>
config.MasterDown := "#Down"
config.WaveUp := "+#Up"       <em>; Shift+Win+UpArrow</em>
config.WaveDown := "+#Down"

<em>; --- Auto Execute Section ---

; DON'T CHANGE ANYTHING HERE (unless you know what you're doing).</em>

#SingleInstance

<em>; Create the Progress window:</em>
global G := GuiCreate("+ToolWindow -Caption -Border +Disabled")
G.MarginX := 0, G.MarginY := 0
opt := "w" config.Width " h" config.Thick " background" config.CW
G.Add("Progress", opt " vMaster c" config.CBM)
G.Add("Progress", opt " vWave c" config.CBW)

<em>; Register hotkeys:</em>
Hotkey config.MasterUp,   () =&gt; ChangeVolume("+")
Hotkey config.MasterDown, () =&gt; ChangeVolume("-")
Hotkey config.WaveUp,     () =&gt; ChangeVolume("+", "Wave")
Hotkey config.WaveDown,   () =&gt; ChangeVolume("-", "Wave")

<em>; --- Function Definitions ---</em>

ChangeVolume(Prefix, ComponentType := "Master")
{
    SoundSet(Prefix config.Step, ComponentType)
    G["Master"].Value := Round(SoundGet("Master"))
    G["Wave"].Value := Round(SoundGet("Wave"))
    G.Show("x" config.PosX " y" config.PosY)
    SetTimer "HideWindow", -config.DisplayTime
}

HideWindow()
{
    G.Hide()
}</pre>
</body>
</html>